package com.pet.mapper;

import com.github.pagehelper.Page;
import com.pet.entity.CheckResult;
import com.pet.entity.PetAdoptApplication;
import com.pet.entity.PetAdoptInfo;
import com.pet.pageDto.PetAdoptPageDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetAdoptMapper {

    Page<PetAdoptInfo> pageQuery(PetAdoptPageDTO dto);

    @Insert("insert into pet_manage_system.pet_adopt_info" +
            "(pet_status, reason, user_id, publish_time,pet_id) " +
            "values " +
            "(#{petStatus},#{reason},#{userId},#{publishTime},#{petId})")
    void insertPetAdoptInfo(PetAdoptInfo e);

    @Delete("delete from pet_manage_system.pet_adopt_info where id = #{id}")
    void deletePetAdoptInfo(Integer id);

    void UpdatePetAdoptInfo(PetAdoptInfo dto);

    @Select("select * from pet_manage_system.pet_adopt_info pai,pet_manage_system.pet_information pi " +
            "where pai.pet_id = pi.id AND pai.user_id = #{currentId}")
    List<PetAdoptInfo> GetPetAdoptInfoById(Integer currentId);

    /**
     * 审核送养申请
     * @param e
     */
    void PetAdoptCheck(CheckResult e);

    /**
     * 查询领养申请
     * @param petId
     */
    @Select("select * from pet_manage_system.pet_adopt_application where pet_id =#{petId}")
    List<PetAdoptApplication> PetAdoptApplicationInfo(Long petId);

    /**
     * 查询宠物id
     * @param currentId
     * @return
     */
    @Select("select pet_id from pet_manage_system.pet_adopt_info where user_id = #{currentId}")
    List<Integer> selectPetIdByUserId(Long currentId);

    /**
     * 查询指定宠物送养详细信息
     * @param id
     * @return
     */
    @Select("select * from pet_manage_system.pet_adopt_info where id = #{id}")
    PetAdoptInfo showPetAdoptInfo(Integer id);

    /**
     * 根据表id 获取宠物id
     * @param id
     */
    @Select("select pet_id from pet_manage_system.pet_adopt_info where id = #{id}")
    Long selectPetIdById(Integer id);

    void PetAdoptCheckByPetId(CheckResult checkResult);

    /**
     * 根据petId删除
     * @param id
     */
    @Delete("delete from pet_manage_system.pet_adopt_info where pet_id =#{id}")
    void deletePetAdoptInfoByPetId(Integer id);

    /**
     * 修改送养状态
     * @param i
     */
    @Update("update pet_manage_system.pet_adopt_info set pet_adopt_status = #{i} where pet_id = #{id}")
    void updatePetAdoptStatus(int i,Integer id);

    /**
     * 根据id查询表application petId
     * @param id
     * @return
     */
    @Select("select pet_id from pet_manage_system.pet_adopt_application where id = #{id}")
    Long selectPetIdByIdFromApplication(Integer id);

    @Delete("delete from pet_manage_system.pet_adopt_info where user_id = #{userId}")
    void deletePetAdoptByUserId(Integer userId);

}
